package vip.xiaonuo.smzq.modular.lifecycle.controller.entity;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

import java.util.stream.Collectors;


import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.smzq.modular.lifecycle.constant.WebResultStatusConstant;
import vip.xiaonuo.smzq.modular.lifecycle.entity.KclCb01Zh;
import vip.xiaonuo.smzq.modular.lifecycle.mapper.entity.KclCb01ZhMapper;
import vip.xiaonuo.smzq.modular.lifecycle.result.ResultWrapper;
import vip.xiaonuo.smzq.modular.lifecycle.result.WebResult;
import vip.xiaonuo.smzq.modular.lifecycle.service.entity.KclCb01ZhService;

/**
 * <p>
 * 字典表1综合 前端控制器
 * </p>
 *
 * @author 于彦飞
 * @since 2024-03-26
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@Api(tags = {"字典表1综合模块"})
@RestController("lifeCycleKclCb01ZhController")
@RequestMapping("/kclCb01Zh" )

public class KclCb01ZhController {
    @Autowired
    private KclCb01ZhService kclCb01ZhService;
    @Autowired
    private KclCb01ZhMapper kclCb01ZhMapper;
    @Resource
    ResultWrapper resultWrapper;

    @ApiOperation(value = "查询所有字典表1综合接口", notes = "查询所有字典表1综合接口")
    @PostMapping(value = "/list")
    public WebResult queryKclCb01ZhList(@RequestBody KclCb01Zh kclCb01Zh) {

        return resultWrapper.getSuccessWebResult(kclCb01ZhService.queryKclCb01ZhList(kclCb01Zh));
    }

    @ApiOperation(value = "分页查询字典表1综合接口", notes = "分页查询字典表1综合接口")
    @PostMapping(value = "/list/page")
    public WebResult queryKclCb01ZhListPage(@RequestBody KclCb01Zh kclCb01Zh) {

        return resultWrapper.getSuccessWebResult(kclCb01ZhService.queryKclCb01ZhListPage(kclCb01Zh));
    }



    @ApiOperation(value = "根据id查询字典表1综合接口", notes = "根据id查询字典表1综合接口")
    @GetMapping(value = "byId/{id}")
    public WebResult queryKclCb01ZhById(@PathVariable("id") String id) {

        KclCb01Zh entity  = kclCb01ZhService.getById(id);
//        DictConvertUtil.convertToDictionary(entity,null);

        return resultWrapper.getSuccessWebResult(entity);
    }

    @ApiOperation(value = "根据id删除字典表1综合接口", notes = "根据id删除字典表1综合接口")
    @PostMapping(value = "d/{id}")
    public WebResult delById(@PathVariable("id")String id) {
        return resultWrapper.getWebResultByDelSuccess(kclCb01ZhService.delKclCb01Zh(id));
    }

    @ApiOperation(value = "根据id批量删除字典表1综合接口", notes = "根据id批量删除字典表1综合接口")
    @PostMapping(value = "/d/batch")
    public WebResult delById(@RequestBody List<String> ids) {
        return resultWrapper.getWebResultByDelSuccess(kclCb01ZhService.delKclCb01ZhBatch(ids));
    }

    @ApiOperation(value = "新增字典表1综合接口", notes = "新增字典表1综合接口")
    @PostMapping(value = "/save")
    public WebResult save(@RequestBody KclCb01Zh kclCb01Zh) {
        boolean isSuccess = kclCb01ZhService.save(kclCb01Zh);
        if(isSuccess){
            return resultWrapper.getWebResultByWebResultStatusConstant(WebResultStatusConstant.SUCCESS_OPERATION, kclCb01Zh.getPkid());
        }
        return resultWrapper.getWebResultByWebResultStatusConstant(WebResultStatusConstant.PROCESS_CREATE, null);
    }

    @ApiOperation(value = "批量新增字典表1综合接口", notes = "批量字典表1综合接口")
    @PostMapping(value = "save/batch")
    public WebResult saveBath(@RequestBody List<KclCb01Zh> kclCb01Zhs) {
        boolean isSuccess = kclCb01ZhService.saveBatch(kclCb01Zhs);
        if(isSuccess){
            List<String> ids = kclCb01Zhs.stream().map(ele->ele.getPkid()).collect(Collectors.toList());
            return resultWrapper.getWebResultByWebResultStatusConstant(WebResultStatusConstant.SUCCESS_OPERATION, ids);
        }
        return resultWrapper.getWebResultByWebResultStatusConstant(WebResultStatusConstant.PROCESS_CREATE, null);
    }

    @ApiOperation(value = "更新用户接口", notes = "id必须有值")
    @PostMapping(value = "/update")
    public WebResult update(@RequestBody KclCb01Zh kclCb01Zh) {
        return resultWrapper.getWebResultByEditSuccess(kclCb01ZhService.updateById(kclCb01Zh));
    }
    @ApiOperation(value = "批量更新字典表1综合接口", notes = "id必须有值")
    @PostMapping(value = "/update/batch")
    public WebResult updateBatch(@RequestBody List<KclCb01Zh> kclCb01Zhs) {
        return resultWrapper.getWebResultByCreateSuccess(kclCb01ZhService.updateBatchById(kclCb01Zhs));
    }
    @ApiOperation(value = "新增或者更新接口", notes = "id无值为新增反之则为更新")
    @PostMapping(value = "/saveOrUpdate")
    public WebResult saveOrUpdate(@RequestBody KclCb01Zh kclCb01Zh) {

        return resultWrapper.getSuccessWebResult(kclCb01ZhService.saveOrUpdate(kclCb01Zh));
    }
    @ApiOperation(value = "批量新增或者更新接口", notes = "id无值为新增反之则为更新")
    @PostMapping(value = "/saveOrUpdate/batch")
    public WebResult saveOrUpdate(@RequestBody List<KclCb01Zh> kclCb01Zhs) {

        return resultWrapper.getSuccessWebResult(kclCb01ZhService.saveOrUpdateBatch(kclCb01Zhs));
    }

}
